import 'package:dio/dio.dart';
import 'package:get/get.dart';

import '../../../bean/bean_train.dart';
import '../../../net/dio_utils.dart';

class TrainUserCheckRecoderController extends GetxController {
  int trainId;

  TrainUserCheckRecoderController(this.trainId);

  TrainUserCheckRecoderEntity _checkRecoderEntity;
  bool _isLoading = true;

  bool getIsLoading() {
    return _isLoading;
  }

  TrainUserCheckRecoderEntity getTrainUserCheckRecoderEntity() {
    return _checkRecoderEntity;
  }

  CancelToken _signCancelToken;

  Future<bool> requestUserCheckRecoderFunction({bool click = false}) async {
    _isLoading = true;
    if (click) {
      update(["root"]);
    }

    if (_signCancelToken != null && !_signCancelToken.isCancelled) {
      _signCancelToken.cancel();
    }
    _signCancelToken = new CancelToken();
    //答题数据
    ResponseInfo statisRresponseInfo = await DioUtils.instance.postRequest(
        url: HttpHelper.userCheckRecoder,
        cancelTag: _signCancelToken,
        jsonMap: {
          "trainId": trainId,
        });
    if (statisRresponseInfo.success) {
      Map data = statisRresponseInfo.data;
      _checkRecoderEntity = TrainUserCheckRecoderEntity.fromMap(data);
    }
    _isLoading = false;
    update(["root"]);
    return true;
  }
}
